package com.jwaoo.chat.session.snap;

import android.content.Context;
import android.util.SparseArray;

import com.jwaoo.chat.Message;

/**
 * Created by jwaoo on 2017/8/9.
 */

public class AutoDescManager {
    private static SparseArray<AutoDescThread> sparseArray = new SparseArray<>();
    public static void startAutoTask(Context context,Message message, AutoDescThread.AutoDescCallback callback){
        if (sparseArray.get(message.getMsgid()) == null) {
            AutoDescThread task = new AutoDescThread(context,message,callback);
            sparseArray.put(message.getMsgid(), task);
            task.start();
        }
        sparseArray.get(message.getMsgid()).setCallback(callback);
    }

    public static void addAutoDescCallback(int key, AutoDescThread.AutoDescCallback callback){
        if (sparseArray.get(key) != null)
            sparseArray.get(key).setCallback(callback);
    }

    public static void clearAutoDescCallback(int key){
        if (sparseArray.get(key) != null)
            sparseArray.get(key).setCallback(null);
    }

    public static void removeTask(int key){
        sparseArray.remove(key);
    }
}
